package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.pojo.TbUser;
import com.qf.result.Result;
import com.qf.service.UserService;

import com.qf.status.StatusCode;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/8/31 16:57
 */
@Controller
@ResponseBody
//@RequestMapping("/user")
public class UserController {
    private UserService userService;
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    @RequestMapping("/userpage")
    public Result findPageUser(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "2") int pageSize){
        PageInfo<TbUser> pageInfo=userService.findPageUser(pageNum,pageSize);
        return Result.OK(pageInfo);
    }
    @RequestMapping("xiugai")
    public TbUser update(){
        TbUser user=userService.findById(15);
        user.setUsername("申志恒3号");
        user.setPassword("123456");
        user.setGender("男");
        userService.updateUser(user);
        TbUser tbUser=userService.findById(15);
        return tbUser;
    }
    @GetMapping("/user/{id}")
    public Result findById(@PathVariable long id){
        TbUser user=userService.findById(id);
        return Result.OK(user);
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable long id){
        userService.deleteById(id);
        return Result.OK(StatusCode.SUCCESS,"删除成功",null);
    }

}
